//
//  forgetPassWorldViewController.m
//  LoveDraw
//
//  Created by 零零壹 on 2017/7/11.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "forgetPassWorldViewController.h"
#import "NSString+MD5Addition.h"

@interface forgetPassWorldViewController ()
@property (weak, nonatomic) IBOutlet UIView *PhoneV;
@property (weak, nonatomic) IBOutlet UIView *PassWorldV;

@property (weak, nonatomic) IBOutlet UIView *MessageV;

@property (weak, nonatomic) IBOutlet UITextField *PhoneTF;
@property (weak, nonatomic) IBOutlet UITextField *PassworldTF;
@property (weak, nonatomic) IBOutlet UITextField *messageTF;

@property (weak, nonatomic) IBOutlet UIButton *ZhaoHuiMiMaBtn;
@property (weak, nonatomic) IBOutlet UIView *SendMsgBtn;
@property (weak, nonatomic) IBOutlet UIButton *SendBtn;


@property(nonatomic,assign)NSInteger index;

@end

@implementation forgetPassWorldViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.index = 60;
    [self setUI];

}

-(void)setUI
{
    self.PhoneV.layer.masksToBounds = YES;
    self.PhoneV.layer.cornerRadius = 5;
    self.PhoneV.layer.borderColor = UIColors(0xDFDFDF).CGColor;
    self.PhoneV.layer.borderWidth = 1;

    self.PassWorldV.layer.masksToBounds = YES;
    self.PassWorldV.layer.cornerRadius = 5;
    self.PassWorldV.layer.borderColor = UIColors(0xDFDFDF).CGColor;
    self.PassWorldV.layer.borderWidth = 1;

    self.MessageV.layer.masksToBounds = YES;
    self.MessageV.layer.cornerRadius = 5;
    self.MessageV.layer.borderColor = UIColors(0xDFDFDF).CGColor;
    self.MessageV.layer.borderWidth = 1;

    self.SendMsgBtn.layer.masksToBounds = YES;
    self.SendMsgBtn.layer.cornerRadius = 5;

    self.ZhaoHuiMiMaBtn.layer.masksToBounds = YES;
    self.ZhaoHuiMiMaBtn.layer.cornerRadius = 5;

}

- (IBAction)SengMSG:(id)sender
{
    [RequestManager HudRequestWithUrl:@"/index.php?g=App&m=Login&a=appSendcode" parmDic:@{@"telephone":self.PhoneTF.text,@"UUID":[DeviceInfo getUUid],@"type":@"2"} requestType:RequestPOST view:self.view Success:^(id data)
    {
        NSTimer *timerAct = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TimerHeadle:) userInfo:nil repeats:YES];
        [timerAct fire];
    } error:^(NSError *error)
    {

    }];
}

-(void)TimerHeadle:(NSTimer *)time;
{

    self.index--;
    NSLog(@"%ld",self.index);
    self.SendBtn.enabled = NO;
    [self.SendBtn setTitle:[NSString stringWithFormat:@"%lds后发送",self.index] forState:(UIControlStateNormal)];
    self.SendBtn.backgroundColor = [UIColor grayColor];
    if (self.index == 0)
    {
        self.SendBtn.enabled = YES;
        self.SendBtn.backgroundColor = UIColors(0xFF8A2F);
        [self.SendBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)];
        [time invalidate];
        self.index = 60;
    }
}

- (IBAction)passworldAct:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)GetMima:(UIButton *)sender
{
    if (self.PassworldTF.text.length == 0) {
        [HUD showText:@"请输入密码" AfterTime:1];
        return;
    };

    [RequestManager RequstWithUrl:@"/index.php?g=App&m=Login&a=forgetpwd" parmDic:@{@"telephonecode":self.messageTF.text,@"telephone":self.PhoneTF.text,@"password":[self.PassworldTF.text stringFromMD5]} requestType:RequestPOST Success:^(id data)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    } error:^(NSError *error) {

    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
